package com.agile.leetcode.tomcat.normalio;

import java.io.IOException;
import java.io.OutputStream;

/**
 * 封装自己的相应对象
 *
 * @Author KD
 * @Date 2021/2/6 14:00
 */
public class MyResponse {
    /**
     * 输出流
     */
    private OutputStream outputStream;

    public MyResponse(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    /**
     * 写出方法
     *
     * @param content
     * @throws IOException
     */
    public void write(String content) throws IOException {
        StringBuilder builder = new StringBuilder();
        builder.append("HTTP/1.1 200 OK\n")
                .append("Content-Type: text/html\n")
                .append("\r\n")
                .append("<html><body>")
                .append(content)
                .append("</body></html>");
        outputStream.write(builder.toString().getBytes());
        outputStream.close();
    }
}
